
function go_post(params){
	var username = $("#username").val();
	var password = $("#password").val();
	$(".error-field-empty").remove();
	if(username == ""){
		appendMessage("username");
		return false;
	}
	if(password == ""){
		appendMessage("password");
		return false;
	}
	var options = $.extend({},{
							messageId: "login-status",
							speedload: 1000,
							speed: 500,
							url: baseURL + "administrator/login/in"
							},params);
	var success = {title: "The login is successful",
				   content: "Welcome to Livemobi Admin Panel",
				   bgcolor1: "#5EB444",
				   bgcolor2: "#268A19",
				   color: "#fff"
				  };
	var error = {
				  title: "The login is invalid",
				  content: "Please check your username and password.",
				  bgcolor1: "#DD5952",
				  bgcolor2: "#BC3E33",
				  color: "#fff"
				};
	var loading = {
					title: "Loading...",
					content: "<img src=\""+ baseURL +"public/templates/administrator/images/loading.gif\" alt=\"\" /> Please wait..., System is processing your request.",
					bgcolor1: "#E5E5E5",
					bgcolor2: "#D4D4D4",
					color: "#000"
				  };
	
	var str  = "<div id=\"login-status-title\"></div>";
		str += "\n<div class=\"login-border\"></div>";
		str += "\n<div id=\"login-status-content\">";
		str += "\n\t<div id=\"login-status-message\">";
		str += "\n\t</div>";
		str += "\n</div>";
	$("#"+options.messageId).empty().append(str);
	addwrap();
	slidedown(loading, 0);	
	$.ajax({
		type: "post",
		url: options.url,
		data: {username: username, password: password},
		complete: function(){
			slideup(options.speedload);
			setTimeout(function(){
				$("#wrapper").remove();
			},options.speedload + 1000);
		},
		success: function(data){
			
			var result = $.parseJSON(data);
			if(result.success){
				slidedown(success, options.speedload + 1000);
				setTimeout(function(){
					$("body").fadeOut("slow");
					window.location.href = baseURL + "administrator";
				}, options.speedload + 2000);
			}else{
				slidedown(error, options.speedload + 1000);
				slideup(options.speedload + 10000);
			}
		}
	});
}

function setTextAndColor(params){
	var settings = $.extend({},{
								title: "",
								content: "",
								bgcolor1: "",
								bgcolor: "",
								color: "#fff", 
								speed: 500
								},params);
	$("#login-status-title").empty().append(settings.title);
	$("#login-status-message").empty().append(settings.content);
	$("#login-status-title").css({"background-color": settings.bgcolor2, "background-image": "linear-gradient(to bottom, "+settings.bgcolor1+" 0px, "+settings.bgcolor2+" 100%)", color: settings.color});
}

function appendMessage(id){
	var errfield  = "<div class=\"error-field-empty\">";
	errfield += "\n\t<div class=\"triangle-error-field\"></div>";
	errfield += "\n\t<div class=\"message-error-field\">Please fill in this field.</div>";
	errfield += "\n</div>";
	$("#"+id).parent(".login-input-field").append(errfield);
}

function slidedown(options, speedload){
	setTimeout(function(){
		setTextAndColor(options);
		$("#login-status").css({visibility: "visible", display: "none"}).show();
		$("#login-status-content").animate({height: "80px"});
	}, speedload);
}

function slideup(speedload){
	setTimeout(function(){
		$("#login-status-content").animate({height: "0px"});
		$("#login-status").slideUp(300);
	}, speedload);
}

function addwrap(){
	var width = $(window).width();
	var height = $(window).height();
	$("body").append("<div id=\"wrapper\"></div>");
	$("#wrapper").css({width: width, height: height, position: "absolute", top: "0", left: "0", "z-index": "9999", cursor: "wait", background: "rgba(0,0,0,0.5)"});
}
$(document).ready(function(){
	var width = $(window).width();
	var height = $(window).height();
	$("body").css({width: width, height: height});
	$("body").click(function(){
		$(".error-field-empty").remove();
	});
});



